package acm.pta7;

import 左哥算法.compare.comparator.MyComparator;

import java.io.IOException;
import java.util.*;

public class Answer {
    public static void main(String[] args) throws IOException {
        Random random=new Random();
        new MyComparator(container -> {
            int n = random.nextInt(10)+1;
            int root=random.nextInt(n);
            Integer[] arr=new Integer[n];
            Arrays.fill(arr,-1);
            for (int i = 0; i < arr.length; i++) {
                int parent;
                do {
                    parent=random.nextInt(n)+1;
                }while (arr[parent-1]==parent||parent==i+1); //父亲的父节点是自己
                arr[i]=parent;
            }
            arr[root]=-1;
            container.addEnd(n).addAllEnd(arr);
        }).compare(小字辈::main,Answer::fun);
    }
//public static void main(String[] args) {
//    fun(null);
//}

    public static void fun(String[] args){
        Scanner in = new Scanner(System.in);
        int x = 0;
        int max=1;
        Vector<Integer> G[] = new Vector[100001];
        int level[] = new int[100001];
        int n = in.nextInt();
        //初始化数组避免出现nullpointexception
        for(int i=0;i<G.length;i++){
            G[i] = new Vector<Integer>();
        }
        for(int i=1;i<=n;i++){
            int t = in.nextInt();
            if(t==-1){
                x = i;
                level[i] = 1;
                continue;
            }
            G[t].add(i);
        }
        max=bfs(x,G,max,level);
        int flag = 0;
        System.out.println(max);
        for(int i=1;i<=n;i++){
            if(level[i]==max){
                if(flag==0){
                    System.out.print(i);
                    flag = 1;
                }else{
                    System.out.print(" "+i);
                }
            }
        }
    }
    public static int bfs(int x, Vector<Integer> G[],int max,int[] level){
        LinkedList<Integer> list = new LinkedList<Integer>();
        list.add(x);
        while(!list.isEmpty()){
            int y = list.getFirst();
            list.removeFirst();
            for(int i=0;i<G[y].size();i++){
                int u = G[y].get(i);
                list.add(u);
                level[u] = level[y]+1;
                max = Math.max(max, level[u]);
            }
        }
        return max;
    }
}
